<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>面向字节编程-cookie</title>
</head>
<body>
    <script>
        // cookie 属于某个域名的 domain 拿不到juejin的cookie
        // console.log(document.cookie, '----------------');
        // cookie 的优点是 每次传输都可以带上, 他是一段文本， 
        // 拿到某一个cookie name 的值
        const cookie = {};
        //一个字符串切完后会变成数组
        const cookieStr = '_ga=GA1.2.1937097148.1625400351; __tea_cookie_tokens_2608=%257B%2522web_id%2522%253A%25226981041326960068100%2522%252C%2522ssid%2522%253A%252206818bd2-0d9f-422b-86a4-1dbb184fb4ca%2522%252C%2522user_unique_id%2522%253A%25226981041326960068100%2522%252C%2522timestamp%2522%253A1625400350455%257D; MONITOR_WEB_ID=8fbd3466-2542-47e5-8d74-04cf138fbcc3; s_v_web_id=verify_l6xbdmje_vglz0oco_nspS_41N3_9mKP_KN5bAR9qmoJ9; passport_csrf_token=659740db550ac6f970b5ec2e90dfe871; passport_csrf_token_default=659740db550ac6f970b5ec2e90dfe871; _tea_utm_cache_2018=undefined; MONITOR_DEVICE_ID=47ff8296-3bbe-47f4-b9ad-1ede9797cee1; _gid=GA1.2.1565144053.1660913699; _tea_utm_cache_2608={%22utm_source%22:%22web1%22%2C%22utm_medium%22:%22feed%22%2C%22utm_campaign%22:%22xunlianying06%22}; tt_scid=aLjEAKcpr-ItFivXTwRT7Lkp3t1Unoo-MkmbHbee1JCLWFRFUTEDd6nShAU.ZPelc976';
        const parseCookie = str =>
          str
            .split(';') //根据分号分割
            .map(v => v.split('='))//切成二维数组,变成的
            // 二位数组 编程一个{} 把数组推平的方法
            .reduce((acc,v) => { 
                acc[v[0]] = v[1]
                return acc
            } , {})
        
        console.log(parseCookie(cookieStr));
    </script>
</body>
</html>